 <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class defective_model extends CI_Model
{
	
	public function __construct()
	{
		parent::__construct();

	}
public function get_view_defective()
	{
	$this->datatables
			->select("case.id as id ,case.case_no,case.date,customer.customer_name,status.name,users.username,customer.mobile,customer.customer_address")
			->from('customer','status','users','case')
             ->join('case','customer.service_id=case.service_id')			
            ->join('status','case.status_id=status.id')	
            ->join('users'	,'case.engineer_id=users.id')	
			->where('case.status_id = 8 OR case.status_id BETWEEN 16 AND 17') 

			->add_column("Actions",
			"<center>			<a href='index.php/admin/defective/collect_docket/$1'>
								<i class='icon-tags'title='Collect docket No.'></i>
								</a>
								</center>", "id")
			
			;
	   return  $this->datatables->generate();
	}		
	
public function get_case($id)
{
$query = $this->db->get_where('case', array('id' => $id));
		return $query;

}	
public function docket_no($data)
{
$this->db->insert('redispatch',$data);

}
public function chk_case($id)
	{
	$this->db->select('redispatch.docket_no');
	$this->db->from('case', 'redispatch' );
	$this->db->join('redispatch', 'case.id= redispatch.case_id '  );
	$this->db->where('case.hp_case',$id);
	$q = $this->db->get();
	return $q;
		
	}
	

public function received_docket($insert)
{ 

$this->db->insert('redispatch_received',$insert);

}
public function get_case_id($id)
{
$this->db->select('case.id,case_no');
	$this->db->from('case' );
	$this->db->where('case.hp_case',$id);
	$q = $this->db->get();
	return $q;
	}
	public function update_case_status($id)
	{
	
	$insert=array('status_id'=>17,);
	$this->db->update('case',$insert,array('id'=>$id));
	
	}
	
public function get_disp_view()
	{
	$this->datatables
			->select("redispatch_received.id as id,case.case_no,redispatch_received.docket_no,redispatch_received.received_date,customer.customer_name,customer.mobile")
			->from('customer','case','received_received')	
			->join('case','customer.service_id=case.service_id')
			->join('redispatch_received','redispatch_received.case_id=case.id')
			//->where('diagnosis.status_id',4)
			->add_column("Actions",
			"<center>			<a href='index.php/admin/defective/assigned_engineer/$1'>
								<i class='icon-edit'></i>
								</a>
								
								</center>", "id")
			
			;
	   return  $this->datatables->generate();
	}
public function get_notassigned()
	{
	$this->datatables
			->select("redispatch_received.id as id,case.case_no,redispatch_received.docket_no,redispatch_received.received_date,customer.customer_name,customer.mobile")
			->from('customer','case','received_received','repair')	
			->join('case','customer.service_id=case.service_id')
			->join('redispatch_received','redispatch_received.case_id=case.id')
			->where('case.status_id',17)
			->add_column("Actions",
			"<center>			<a href='index.php/admin/defective/assigned_engineer/$1'>
								<i class='icon-edit'title='Assign Engineer'></i>
								</a>
								
								</center>", "id")
			
			;
	   return  $this->datatables->generate();
	}		
public function get_engineer()
	{
	$this->db->select('users.*');
	$this->db->from('users', 'users_groups' );
	$this->db->join('users_groups', 'users.id= users_groups.user_id   '  );
	$this->db->where('users_groups.group_id',2);
	$q = $this->db->get();
		if($q->num_rows() > 0) {
			foreach (($q->result()) as $row) {
				$data[] = $row;
			}
			return $data;
			}
	}		
public function detail_redispatch($id)
{
$this->db->select('redispatch_received.case_id,redispatch_received.case_no,redispatch_received.docket_no');
	$this->db->from('redispatch_received' );
	$this->db->where('redispatch_received.id',$id);
	$q = $this->db->get();
	return $q;

}
public function insert_repair($insert)
{
$this->db->insert('repair',$insert);
}
public function update_case($id)
{
$insert=array('status_id'=>18,);
$this->db->update('case',$insert,array('id'=>$id,));
}


	
}	

?>	
	